package com.dragon.flow.vo;

import com.dragon.flow.enm.flowable.CommentTypeEnum;
import com.dragon.flow.threadLocal.LoginUserContext;
import com.dragon.flow.vo.login.PlusLoginUserVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @title:
 * @author: bruce.liu
 * @since: 2024/9/16 9:02
 */
@Data
public abstract class PlusBaseVo {
    //登录的用户code
    @NotNull
    private String userCode;
    //登录用户的角色标识列表
    @NotNull
    private List<String> roleSns;
    //登录者的公司Id
    @NotNull
    private String companyId;
    //是否开启租户
    private boolean tenantEnable;
    /**********************任务相关的参数**********************/
    /**
     * 任务id 必填
     */
    @ApiModelProperty(value = "任务id", required = true)
    private String taskId;
    /**
     * 节点id
     */
    @ApiModelProperty(value = "节点id")
    private String activityId;
    @ApiModelProperty(value = "节点名称")
    private String activityName;
    /**********************审批意见的参数**********************/
    /**
     * 审批意见 必填
     */
    @ApiModelProperty(value = "审批意见", required = true)
    private String message;
    /**
     * 审批意见类型
     */
    @ApiModelProperty(value = "审批意见类型", required = true)
    private CommentTypeEnum commentTypeEnum;

    /**
     * 流程实例的id
     */
    @ApiModelProperty(value = "流程实例的id", required = true)
    private String processInstanceId;

    /**
     * 赋值查询参数
     */
    private PlusLoginUserVo getUserInfo() {
        PlusLoginUserVo loginUser = LoginUserContext.getUser();
        if (loginUser != null) {
            return loginUser;
        }
        return null;
    }

    public String getUserCode() {
        if (StringUtils.isBlank(userCode)) {
            PlusLoginUserVo userInfo = getUserInfo();
            if (userInfo != null) {
                this.userCode = userInfo.getUserCode();
            }
        }
        return userCode;
    }

    public List<String> getRoleSns() {
        if (CollectionUtils.isNotEmpty(roleSns)) {
            PlusLoginUserVo userInfo = getUserInfo();
            if (userInfo != null) {
                this.roleSns = userInfo.getRoleSns();
            }
        }
        return roleSns;
    }

    //添加登录用户信息
    public void addLoginUserInfo(PlusLoginUserVo loginUserInfo) {
        this.userCode = loginUserInfo.getUserCode();
        this.roleSns = loginUserInfo.getRoleSns();
        this.companyId = loginUserInfo.getCompanyId();
    }

}
